using System;
using System.Collections.Generic;
using System.Reflection;
namespace AppToolKit.Core.Xml
{
	public class MappingAttributeHandler
	{
		private Dictionary<string, string> attributes_;
		public Dictionary<string, string> Attributes
		{
			get
			{
				if (this.attributes_ == null)
				{
					this.attributes_ = new Dictionary<string, string>();
				}
				return this.attributes_;
			}
		}
		public void OnAttribute(object instance, string element, string name, string value)
		{
			Type type = instance.GetType();
			object obj = instance;
			if (this.Attributes.ContainsKey(name) && !string.IsNullOrEmpty(value))
			{
				string text = this.Attributes[name];
				string[] array = text.Split(new char[]
				{
					'.'
				});
				int i = 0;
				PropertyInfo property;
				if (array.Length > 1)
				{
					while (i < array.Length - 1)
					{
						string name2 = array[i];
						property = type.GetProperty(name2);
						obj = property.GetValue(obj, null);
						type = obj.GetType();
						i++;
					}
				}
				property = type.GetProperty(array[i]);
				if (property == null)
				{
					throw new XmlParserException(string.Format("MappingAttribute:{0}不在存{1}", instance.GetType(), this.Attributes[name]));
				}
				property.SetValue(obj, value, null);
			}
		}
	}
}
